import os
import io

title = '图床'


def make(s):
    d = os.listdir('./img')
    pictures = ["s", "h", "y"]

    with open('index.html', 'w', encoding="utf-8") as f:
        pictures.clear()
        f.write(
            '<!DOCTYPE html><html>	<head>		<title>{0}</title>		<title>{1}</title>		<meta '
            'http-equiv="content-type" content="text/html; charset=UTF-8">		<script type="text/javascript" '
            'src="js/jquery-3.4.1.min.js"></script>		<link rel="stylesheet" type="text/css" href="css/my.css"/>	'
            '	<script type="text/javascript" src="js/myScript.js"></script>	</head>	<body>				<div '
            'id="main">			<div id="bar">'.format(
                title, s))

        for i in d:
            if i != '.git' and i != 'list.py' and i != 'index.html':
                if os.path.isdir(i):
                    # os.chdir(i)
                    # make(s + i + '/')
                    # os.chdir('..')
                    f.write('<input class="barbtn" type="button" name="{0}" value="{0}">\n'.format(i))
                else:
                    f.write('<input class="barbtn" type="button" name="{0}" value="{0}">\n'.format(i))

        f.write('</div>			<div>')

        for i in d:
            if i != '.git' and i != 'list.py' and i != 'index.html':
                if os.path.isdir(i):
                    f.write('')
                else:
                    f.write('<div id="{0}" class="photos">'.format(i))
                    photos = os.listdir("img/" + i)
                    for photo in photos:
                        f.write('<img src="img/{0}/{1}" class="photo" title="点击查看大图" />\n'.format(i, photo))
                f.write('</div>')
        f.write('</div></body></html>')


make('https://ifshy.gitee.io/pic/img/')
print('DONE')
